package com.koicarp.university.graduate.web.controller.schoolInfoManage;

import com.koicarp.university.graduate.auth.annotation.OperLog;
import com.koicarp.university.graduate.auth.constant.ModuleNameEnum;
import com.koicarp.university.graduate.auth.constant.OperateLogTypeEnum;
import com.koicarp.university.graduate.service.entity.schoolInfoManage.Academy;
import com.koicarp.university.graduate.service.service.schoolInfoManage.IAcademyService;
import com.koicarp.university.graduate.service.vo.schoolInfoManage.AcademyVo;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【学校基本信息：学院管理表】(Academy)表控制层
 *
 * @author liutao
 * @since 2020-09-03 19:49:30
 */
@Slf4j
@RestController
@RequestMapping("academy")
@RequiredArgsConstructor
@Api(tags = "(学院管理表)表控制层")
public class AcademyController {
    /**
     * 服务对象
     */
    private final IAcademyService academyService;

    @PostMapping("getAllAcademyInfo")
    @ApiOperation(value = "查询所有学院信息",notes = "查询所有学院信息")

    public UniversityResponse getAllAcademyInfo(Academy academy){
        UniversityResponse response=null;
        try{
            response = academyService.getAllAcademyInfo(academy);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("getAcademyInfoWithPage")
    @ApiOperation(value = "学院信息查询-普通查询，分页",notes = "学院信息查询-普通查询，分页")
    public UniversityResponse getAcademyInfoWithPage(AcademyVo vo){
        UniversityResponse response=null;
        try{
            if (vo.getSort().equals("+id")){
                vo.setSort("asc");
            }else{
                vo.setSort("desc");
            }
            response = academyService.getAcademyInfoWithPage(vo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("saveAcademyInfo")
    @ApiOperation(value = "学院信息增加(单个)" ,notes = "学院信息增加(单个)")
    @OperLog(moduleName = ModuleNameEnum.SchoolAca,type = OperateLogTypeEnum.CREATE,operDesc = "学院信息增加（单个）")
    public UniversityResponse saveAcademyInfo(@RequestBody Academy academy){
        UniversityResponse response=null;
        try{
            response = academyService.insert(academy);
        }catch (Exception e){
            log.error("增加失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("removeAcademyInfo")
    @ApiOperation(value = "删除学院信息(单个)" ,notes = "删除学院信息（单个）")
    @OperLog(moduleName = ModuleNameEnum.SchoolAca,type = OperateLogTypeEnum.DELETE,operDesc = "删除学院信息（单个）")
    public UniversityResponse removeAcademyInfo(@RequestBody Academy academy){
        UniversityResponse response=null;
        try{
            response = academyService.deleteById(academy.getId());
        }catch (Exception e){
            log.error("删除失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("removeListInfo")
    @ApiOperation(value = "删除学院信息(多个)" ,notes = "删除学院信息（多个）")
    @OperLog(moduleName = ModuleNameEnum.SchoolAca,type = OperateLogTypeEnum.DELETE,operDesc = "删除学院信息（多个）")
    public UniversityResponse removeListInfo(@RequestBody List<Integer> idList){
        UniversityResponse response=null;
        try{
            response = academyService.deleteList(idList);
        }catch (Exception e){
            log.error("删除失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("modifyAcademyInfo")
    @ApiOperation(value = "修改学院信息" ,notes = "修改学院信息")
    @OperLog(moduleName = ModuleNameEnum.SchoolAca,type = OperateLogTypeEnum.UPDATE,operDesc = "修改学院信息")
    public UniversityResponse modifyAcademyInfo(@RequestBody Academy academy){
        UniversityResponse response=null;
        try{
            response = academyService.update(academy);
        }catch (Exception e){
            log.error("修改失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }



}